#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 10;
int n, m;
ll a[N], l, r;

bool check(ll x) {
	ll sum = 0, cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (sum + a[i] <= x) sum += a[i];
		else {
			sum = a[i];
			cnt++;
		}
	}
	return cnt >= m;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		l = max(l, a[i]);
		r += a[i];
	}
	while (l <= r) {
		ll mid = (l + r + 1) >> 1;
		if (check(mid)) l = mid + 1;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}